package com.aegean.MonitorExamSYS.android.action;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.sql.SQLException;

import javax.annotation.Resource;

import org.apache.struts2.ServletActionContext;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.aegean.MonitorExamSYS.android.business.AndroidBusiness;
import com.aegean.MonitorExamSYS.examinee.business.ExamineeBusiness;
import com.aegean.MonitorExaxSYS.model.ExamineeValue;
import com.aegean.MonitorExaxSYS.model.UserValue;
import com.opensymphony.xwork2.ActionSupport;

@Controller("UserPhotoForAndroid")
@Scope("prototype")
public class UserPhotoForAndroid extends ActionSupport {
	private int user_Id;
	private InputStream user_Photo;
	private String photoName;
	private String photoType;
	private UserValue user;
	@Resource
	AndroidBusiness business;
	public int getUser_Id() {
		return user_Id;
	}

	public void setUser_Id(int user_Id) {
		this.user_Id = user_Id;
	}

	public InputStream getUser_Photo() {
		return user_Photo;
	}

	public void setUser_Photo(InputStream user_Photo) {
		this.user_Photo = user_Photo;
	}

	public String getPhotoName() {
		return photoName;
	}

	public void setPhotoName(String photoName) {
		this.photoName = photoName;
	}

	public String getPhotoType() {
		return photoType;
	}

	public void setPhotoType(String photoType) {
		this.photoType = photoType;
	}
	public InputStream getDownload() {
		try {
			user = business.showPhoto(user_Id);
			user_Photo = user.getUser_Photo().getPhoto().getBinaryStream();
			photoName = user.getUser_Photo().getPhoto_Name();
			photoType = user.getUser_Photo().getPhoto_Type();
			return user_Photo;
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			return null;
		}
	}

	@Override
	public String execute() throws Exception {
		return SUCCESS;
	}

}
